class code3 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        //避免删头节点，引入傀儡节点
        ListNode cur = new ListNode(0,head);
        ListNode fast = cur;
        ListNode slow = cur;
        //先让fast走n步
        while(n-- > 0) {
            fast = fast.next;
        }
        //slow到要删的前一个
        while(fast !=null && fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }

        slow.next = slow.next.next;

        return cur.next;
    }
}